package com.guigu.www.cxk.controller;

import com.guigu.www.cxk.service.CXKHealthManagerService;
import com.guigu.www.pojo.ChatTable;
import com.guigu.www.pojo.HealthManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("manager")
public class CXKHealthManagerController {

    @Autowired
    CXKHealthManagerService service;

    /*查询专家*/
    @PostMapping
    @ResponseBody
    public List<HealthManager> selectManger(){
       return service.selectManager();
    }

    /*添加聊天总表*/
    @PostMapping("chattable/{uid}/{id}")
    @ResponseBody
    public int chattable(@PathVariable int uid,@PathVariable int id){
        System.out.println(uid+""+id);
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = dateFormat.format(date);
        ChatTable chatTable = new ChatTable();
        chatTable.setMemId(uid);
        chatTable.setHmId(id);
        chatTable.setChatTaState(0);
        chatTable.setChatTaCreateTime(format);
        ChatTable chatTables = service.selectChatTable(uid,id);
        System.out.println(chatTables);
        if(chatTables == null) {
            service.saveChatTable(chatTable);
        }
        return 0;
    }

    @PostMapping("/addConsultMsg")
    @ResponseBody
    public Integer addConsultMsg(Integer chatTaId, Integer conMesType, String conMesContent, Integer conMesState, String conMesAccount){
        return service.addConsultMsg(chatTaId, conMesType,conMesContent,conMesState,conMesAccount);
    }
}
